//
//  MyMainViewController.m
//  IMDome
//
//  Created by 崔志伟 on 2020/8/22.
//  Copyright © 2020 czw. All rights reserved.
//

#import "MyMainViewController.h"
#import "MyDetailViewController.h"
#import "CustomPromptView.h"

#import "UserModel.h"


@interface MyMainViewController ()
@property (weak, nonatomic) IBOutlet UIImageView *headerIMgView;
@property (weak, nonatomic) IBOutlet UILabel *nameLabel;
@property (weak, nonatomic) IBOutlet UILabel *timeLabel;
@property (nonatomic,strong) UserModel  * userModel ;

@end

@implementation MyMainViewController
- (void)viewWillAppear:(BOOL)animated {
    [self.navigationController setNavigationBarHidden:YES animated:animated];
    [super viewWillAppear:animated];
    [self laodData];
}
- (void)viewWillDisappear:(BOOL)animated {
    [self.navigationController setNavigationBarHidden:NO animated:animated];
    [super viewWillDisappear:animated];
}
- (void)viewDidLoad {
    [super viewDidLoad];
}

- (void)laodData{
     NSMutableDictionary *params  = [NSMutableDictionary dictionary];
    [params setObject:[APPUserDataManager shareInstance].userId forKey:@"userId"];
     [BaseServiceManager getRequest:@"user/getUser" params:params startBlock:^{
         [self showRequestHUDView];
      } successBlock:^(ResponseBaseModel * _Nonnull responseModel) {
          [self hideRequestHUDView];
          NSDictionary*dataDic = responseModel.data;
          self.userModel= [UserModel mj_objectWithKeyValues:dataDic];
          if (kStringIsEmpty(self.userModel.name)) {
              self.nameLabel.text = self.userModel.account;
          }else{
              self.nameLabel.text = self.userModel.name;
          }
      } failureBlock:^(NSError * _Nonnull error, NSString * _Nonnull msg) {
          [self hideRequestHUDView];
      }];
    
}
- (IBAction)editAction:(id)sender {
    MyDetailViewController *detailVC = [MyDetailViewController new];
    [self.navigationController pushViewController:detailVC animated:YES];
    
}
- (IBAction)outLoginAction:(id)sender {
    [CustomPromptView showPromptViewTitle:@"确认要退出当前账号吗？" sureBlcok:^{
        [APPUserDataManager shareInstance].token = @"";
        [APPUserDataManager shareInstance].userId = @"";
        [[NSUserDefaults standardUserDefaults] removeObjectForKey:IM_TOKEN_KEY];
        [[NSUserDefaults standardUserDefaults] removeObjectForKey:IM_USER_ID_KEY];
        [[NSNotificationCenter defaultCenter] postNotificationName:USER_LOGOUT_SUCCESS_KEY object:nil];
    }];
}

@end
